package cn.edu.sdjzu.xg.bysj.service;

import cn.edu.sdjzu.xg.bysj.dao.GraduateProjectDao;
import cn.edu.sdjzu.xg.bysj.domain.GraduateProject;
import cn.edu.sdjzu.xg.bysj.domain.GraduateProjectStatus;
import cn.edu.sdjzu.xg.bysj.domain.Teacher;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

public final class GraduateProjectService {
	private GraduateProjectDao graduateProjectDao= GraduateProjectDao.getInstance();
	private static GraduateProjectService graduateProjectService = new GraduateProjectService();
	
	//Singleton
	private GraduateProjectService(){

	}

	public static GraduateProjectService getInstance(){
		return graduateProjectService;
	}

	//获取所有课题(参数指定的)
	public Collection<GraduateProject> findAll(List conditionList,
											   Pagination pagination)
			throws SQLException {
		Connection connection = JdbcHelper.getConn();
		Collection<GraduateProject> graduateProjects = graduateProjectDao.findAll(conditionList,pagination,connection) ;
		JdbcHelper.close(connection);
		return graduateProjects;
	}

	//获得id对应的课题
	public GraduateProject find(Integer id) throws SQLException{
		Connection connection = JdbcHelper.getConn();
		GraduateProject graduateProject = graduateProjectDao.find(id,connection);
		JdbcHelper.close(connection);
		return graduateProject;
	}

	//更新一个课题
	public boolean update(GraduateProject graduateProject) throws SQLException{
		Connection connection = JdbcHelper.getConn();
		Boolean updated = graduateProjectDao.update(graduateProject,connection);
		JdbcHelper.close(connection);
		return updated ;
	}

	//增加一个课题
	public boolean add(GraduateProject graduateProject) throws SQLException{
		Connection connection = JdbcHelper.getConn();
		boolean result= graduateProjectDao.add(graduateProject,connection);
		JdbcHelper.close(connection);
		return  result;
	}


	//删除一个课题
	public boolean delete(int id) throws SQLException{
		Connection connection = JdbcHelper.getConn();
		boolean deleted = graduateProjectDao.delete(id, connection);
		JdbcHelper.close(connection);
		return deleted;
	}
	
}
